package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;

@Mapper
public interface OrderMapper {

    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    Page<Orders> getOrdersByUserId(OrdersPageQueryDTO dto);

    @Select("select * from orders where id = #{id}")
    OrderVO getOrderByOrderId(Long id);

    @Update("update orders set status = #{status} where id = #{id}")
    void cancelOrder(Long id);

    Page<Orders> getByPage(OrdersPageQueryDTO dto);

    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Update("update orders set status = #{status}, " +
            "cancel_time = #{cancelTime} ,cancel_reason = #{cancelReason} where id = #{id}")
    void cancelOrderByDto(Orders orders);

    @Update("update orders set status = #{status} where id = #{id}")
    void confirm(Orders order);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getStatusAndOrderTimeByTime(Integer status, LocalDateTime time);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getStatusAndOrderTimeBySendTime(Integer status, LocalDateTime time);

    Double getSumByMap(HashMap<Object, Object> map);

    Integer getOrderCount(LocalDateTime begin, LocalDateTime end, Integer status);

    List<GoodsSalesDTO> top10(LocalDateTime begin, LocalDateTime end);

    @Select("select count(*) from orders")
    Integer getAll();

    @Select("select count(id) from orders where status = #{status}")
    Integer getOrderByStatus(Integer status);
}















